package com.example.demo.drools.base;

import java.io.Serializable;

/**
 * WebApi接口对象.
 */
public class Result<T> implements Serializable {

	private static final long serialVersionUID = 7314670530670292902L;
	/**
     * 结果描述
     */
    private String message;
    /**
     * 结果编码
     */
    private String code;
    /**
     * 业务数据
     */
    private T data;

    public Result() {
    	
    }

    public static <T> Result<T> success() {
        return success(null);
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setData(data);
        result.setCode("200");
        result.setMessage("操作成功");
        return result;
    }


    public static <T> Result<T> fail(String code, String message) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
    
    /**
     * 操作是否成功
     * @return
     */
    public boolean isSuccess() {
    		if("200".equals(code)) {
    			return true;
    		}else{
    			return false;
    		}
    }
    
    
    public static <T> Result<T> fail(String message) {
        return fail("400", message);
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

	@Override
	public String toString() {
		return "Result [message=" + message + ", code=" + code + ", data=" + data + "]";
	}
}
